package pl.kosmowska.ewelina.server.jdo;

import java.util.Date;

import javax.jdo.annotations.Extension;
import javax.jdo.annotations.IdGeneratorStrategy;
import javax.jdo.annotations.PersistenceCapable;
import javax.jdo.annotations.Persistent;
import javax.jdo.annotations.PrimaryKey;
import javax.jdo.annotations.Version;
import javax.jdo.annotations.VersionStrategy;
import com.google.appengine.api.datastore.Key;
import com.google.appengine.api.datastore.KeyFactory;

@PersistenceCapable
@Version(strategy = VersionStrategy.VERSION_NUMBER, column = "version", extensions = { @Extension(vendorName = "datanucleus", key = "key", value = "version") })
public class OutcomeData implements DatabaseEntity<String> {

	/**
	 * primary id transposed to web safe id (base64) for transport
	 */
	@PrimaryKey
	@Persistent(valueStrategy = IdGeneratorStrategy.IDENTITY)
	private Key key;

	/**
	 * mandatory parameter used with request factory
	 * 
	 * @Version in JPA annotation
	 */
	@Persistent
	private Long version;

	/**
	 * entity owner - the person who's logged in
	 */
	@Persistent
	private Long userId;

	@Persistent
	private String name;

	@Persistent
	private float value;

	@Persistent
	private String category;

	@Persistent
	private String priority;

	@Persistent
	private Date date;

	@Persistent
	private boolean multiple;

	@Persistent
	private String groupKey;

	@Persistent
	private String sponsorKey;

	@Persistent
	private Date repeatEndDate;

	@Persistent
	private int repeatInterval;


	
	public String getSponsorKey() {
		return sponsorKey;
	}

	public void setSponsorKey(String sponsorKey) {
		this.sponsorKey = sponsorKey;
	}

	public String getGroupKey() {
		return groupKey;
	}

	public void setGroupKey(String groupKey) {
		this.groupKey = groupKey;
	}

	public int getRepeatInterval() {
		return repeatInterval;
	}

	public void setRepeatInterval(int repeatInterval) {
		this.repeatInterval = repeatInterval;
	}
	public Date getRepeatEndDate() {
		return repeatEndDate;
	}

	public void setRepeatEndDate(Date repeatEndDate) {
		this.repeatEndDate = repeatEndDate;
	}

	public boolean isMultiple() {
		return multiple;
	}

	public void setMultiple(boolean multiple) {
		this.multiple = multiple;
	}
	public String getPriority() {
		return priority;
	}

	public void setPriority(String priority) {
		this.priority = priority;
	}
	
	@Override
	public String toString() {
		StringBuilder sb = new StringBuilder();
		sb.append("key=" + key + ",");
		sb.append("version=" + version + ",");
		sb.append("userId=" + userId + ",");
		sb.append("name=" + name + ",");
		sb.append("value=" + value + ",");
		sb.append("cateogry=" + category + ",");
		sb.append("date =" + date.toString());
		// sb.append("items={ " + items + " } ");
		return sb.toString();
	}

	public float getValue() {
		return value;
	}

	public void setValue(float value) {
		this.value = value;
	}

	public String getCategory() {
		return category;
	}

	public void setCategory(String category) {
		this.category = category;
	}

	public Date getDate() {
		return date;
	}

	public void setDate(Date date) {
		this.date = date;
	}

	public void setId(String id) {
		if (id == null) {
			return;
		}
		key = KeyFactory.stringToKey(id);
	}

	public String getId() {
		String id = null;
		if (key != null) {
			id = KeyFactory.keyToString(key);
		}
		return id;
	}

	public void setVersion(Long version) {
		this.version = version;
	}

	public Long getVersion() {
		if (version == null) {
			version = 0l;
		}
		return version;
	}

	public void setUserId(Long userId) {
		this.userId = userId;
	}

	public Long getUserId() {
		return userId;
	}

	public void setName(String name) {
		this.name = name;
	}

	public String getName() {
		return name;
	}

	public Key getKey() {
		return key;
	}

	public void setKey(Key key) {
		this.key = key;
	}



}
